# board = [["X","X","X","X"],["X","O","O","X"],["X","X","O","X"],["X","O","X","X"]]
# board=[["O","O","O","O","X","X"],["O","O","O","O","O","O"],["O","X","O","X","O","O"],["O","X","O","O","X","O"],["O","X","O","X","O","O"],["O","X","O","O","O","O"]]
board=[["X","X","X","X"],["X","O","O","X"],["X","X","O","X"],["X","O","X","X"]]
print(board)
def solve(board):
    direction=[-1,0,1,0,-1]
    #行号和列号
    row_len,col_len=len(board),len(board[0])
    if row_len<=2 or col_len<=2:
        return None
    #使用队列实现广度优先遍历
    queue=[]
    for i in range(row_len):
        #行遍历和列遍历
        for j in range(col_len):
            if i==0 or i==row_len-1 or j==0 or j==col_len-1:
                if board[i][j]=="O":
                    #将坐标点存入其中
                    board[i][j]="#"
                    queue.append([i,j])
    print(queue)
    while queue:
        #此轮需要进行的轮数
        queue_len=len(queue)
        while queue_len>0:
            #弹出其中的坐标
            [r,c]=queue.pop(0)
            for k in range(4):
                x,y=r+direction[k],c+direction[k+1]
                if x>=0 and x<row_len and y>=0 and y<col_len and board[x][y]=="O":
                    board[x][y]="#"
                    queue.append([x,y])
            queue_len-=1
    for i in range(row_len):
        for j in range(col_len):
            if board[i][j]=="O":
                board[i][j]="X"
            if board[i][j]=="#":
                board[i][j]="O"
    print(board)





solve(board)